/* Gauge - Performance Measurement Framework for Mobile Platforms
 * Copyright (C) 2013, Juha Hytonen <juha.a.hytonen@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.gauge.GaugeAgent;

import org.gauge.Log;
import org.gauge.MeasurementStorage;
import org.gauge.Probe;

/**
 * Reads a measurement from a probe on given intervals and stores it
 * into the measurement storage.
 * 
 * @see Probe
 * @see MeasurementStorage
 */
public final class PeriodicProbeRunner extends AbstractPeriodicRunner {

	private Probe probe;
	
	public PeriodicProbeRunner(Probe probe, int millisecsBetweenMeasurements) {
		super(millisecsBetweenMeasurements);
		this.probe = probe;
	}
	
	public String GetProbeClassName() {
		return probe.getClass().getName();
	}

	protected final void onExecute() {
		try {
			MeasurementStorage.Add(probe.GetMeasurement());
		}
		catch(Exception e) {
			Log.AddError(e.toString());
		}
	}
	
}
